class PicturesController < ApplicationController
	layout false
	def new
		@picture=Picture.new()
	end

	def create
		picture=Picture.new(set_params)
		if picture.save
     	path=SavePicture.make_user_dir(picture.id,"Images")
			File.open("public/store/#{picture.id}/Images/images.png", "w+b", 0666) {|f| f.write params[:picture][:photo].read}
			redirect_to pictures_path
		else
			new_picture_path
		end
	end
	def index
		@pictures=Picture.all
	end
	def show
		@url=SavePicture.show_path(params[:id],"Images")
		@picture=Picture.find(params[:id])
	end
	private
	def set_params
		params.require(:picture).permit(:name,:photo)
	end
end
